#include "queryfx.h"
#include "ui_queryfx.h"

queryfx::queryfx(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::queryfx)
{
    ui->setupUi(this);

    this->setWindowFlags(Qt::WindowStaysOnTopHint);
    this->setAttribute(Qt::WA_QuitOnClose, false);
    this->setWindowModality(Qt::ApplicationModal);
}

queryfx::~queryfx()
{
    delete ui;
}

void queryfx::showEvent(QShowEvent *event){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    QList<QString> realyqList;
    QList<QString> realNameList;
    QList<QString> realTypeList;
    QList<QString> realSystemList;

    QString sql="Select Name From ItemCode where  DicCode=14";//分析仪器
    query.exec(sql);
    ui->comboBox->blockSignals(true);
    ui->comboBox->DataClear();
    ui->comboBox->addDataItem("全部");
    realyqList.append("全部");
    while (query.next())
    {
        QString realPos=query.value("Name").toString();

        if(!realyqList.contains(realPos))
        {
            realyqList.append(realPos);
            ui->comboBox->addDataItem(realPos);
        }
    }
    ui->comboBox->setSelectedData(realyqList);
    ui->comboBox->blockSignals(false);


    sql="Select Name From ItemCode where  DicCode=15";//试剂盒类型
    query.exec(sql);
    ui->comboBox_2->blockSignals(true);
    ui->comboBox_2->DataClear();
    ui->comboBox_2->addDataItem("全部");
    realNameList.append("全部");
    while (query.next())
    {
        QString realPos=query.value("Name").toString();

        if(!realNameList.contains(realPos))
        {
            realNameList.append(realPos);
            ui->comboBox_2->addDataItem(realPos);
        }
    }

    ui->comboBox_2->setSelectedData(realNameList);
    ui->comboBox_2->blockSignals(false);

    sql="Select Name From ItemCode where  DicCode=12";//试剂盒名称
    query.exec(sql);
    ui->comboBox_3->blockSignals(true);
    ui->comboBox_3->DataClear();
    ui->comboBox_3->addDataItem("全部");
    realTypeList.append("全部");
    while (query.next())
    {
        QString realPos=query.value("Name").toString();

        if(!realTypeList.contains(realPos))
        {
            realTypeList.append(realPos);
            ui->comboBox_3->addDataItem(realPos);
        }
    }
    ui->comboBox_3->setSelectedData(realTypeList);
    ui->comboBox_3->blockSignals(false);

    sql="Select Name From ItemCode where  DicCode=4";//体系
    query.exec(sql);
    ui->comboBox_4->blockSignals(true);
    ui->comboBox_4->DataClear();
    ui->comboBox_4->addDataItem("全部");
    realSystemList.append("全部");
    while (query.next())
    {
        QString realPos=query.value("Name").toString();

        if(!realSystemList.contains(realPos))
        {
            realSystemList.append(realPos);
            ui->comboBox_4->addDataItem(realPos);
        }
    }
    ui->comboBox_4->setSelectedData(realSystemList);
    ui->comboBox_4->blockSignals(false);
}

void queryfx::on_pushButton_3_clicked()
{
    jyfxy=ui->comboBox->currentText();
    reagentKitType=ui->comboBox_2->currentText();
    reagentKitName=ui->comboBox_3->currentText();
    system=ui->comboBox_4->currentText();
    memo=ui->lineEdit->text();
    this->close();
}

void queryfx::on_pushButton_2_clicked()
{
    this->close();
}
